﻿using System;
using System.Collections.Generic;
using ZhiKeDuoServer.Model;
using IDAL;
using System.Data;

namespace DAL
{
    public class SaleInfoService : Base<SaleInfo>
    {
        public SaleInfo GetPreModel(string oper)
        {
             return DB.Client.Queryable<ZhiKeDuoServer.Model.SaleInfo>().Where(t => t.Oper == oper).OrderBy("Id desc").First();
        }

        public bool Exists(string pid)
        {
            return DB.Client.Queryable<ZhiKeDuoServer.Model.SaleInfo>().Where(t => t.Pid == pid).Any();
        }

        public bool Delete(string pid)
        {
            return DB.Client.Deleteable<ZhiKeDuoServer.Model.SaleInfo>().Where(t => t.Pid == pid).ExecuteCommandHasChange();
        }

        public SaleInfo GetModel(string pid)
        {
            return DB.Client.Queryable<ZhiKeDuoServer.Model.SaleInfo>().Where(t => t.Pid == pid).First();
        }

        public DataTable Jiaoban(int banci, int shop, String opt)
        {
     

            var list3 = DB.Client.Ado.GetDataTable("select  sum(saleinfo.PriceSum) as money , payment.Name  from saleinfo " +
                "inner join  payment on saleinfo.paytype = payment.id " +
                " where saleinfo.banci="+ banci +
                " and saleinfo.shop="+shop+
                " and saleinfo.Oper='" + opt +
                "' group by  saleinfo.paytype");
            return list3;
        }
        public DataTable GetSql(String sql)
        {


            var list3 = DB.Client.Ado.GetDataTable(sql);
            return list3;
        }
        public DataSet GetDataSql(String sql)
        {


            var list3 = DB.Client.Ado.GetDataSetAll(sql);
            return list3;
        }
    }
}